package NC17_最长回文子串;

import java.util.*;

public class Solution {
    public int getLongestPalindrome(String A, int n) {
        // write code here
        int maxLen = 0;
        for (int i = 0; i < n; i++){
            for (int j = i + 1; j < n;j++){
                String str = A.substring(i, j);
                if (isPalindrome(str) && str.length() > maxLen){
                    maxLen = str.length();
                }
            }
        }
        return maxLen;
    }

    private boolean isPalindrome(String str) {
        int len = str.length();
        for (int i = 0; i < len / 2; i++){
            if (str.charAt(i) != str.charAt(len - i -1)){
                return false;
            }
        }
        return true;
    }
}